fix(zustand): v5 selector stability issues#4539
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryMedium Risk Overview Adds stable empty fallback constants for sub-block values ( Introduces a new Reviewed by Cursor Bugbot for commit 8ca96c2. Configure here. |
Greptile SummaryThis PR addresses Zustand v5 selector stability regressions that could cause infinite render loops during workflow loading, by tightening store subscriptions across several components and adding a CI script to prevent future regressions.
Confidence Score: 5/5Safe to merge — all application changes are targeted subscription narrowing with no behavioral side-effects, and the new CI script is additive. Each component change is a mechanical narrowing of an existing subscription: replacing whole-store destructuring with a field selector, or wrapping a returned object with useShallow for shallow comparison. The module-level empty constants correctly fix the root cause of reference instability. The useShallow(useCallback(..., [blockId])) composition is valid: useCallback memoizes on [blockId], and useShallow's internal useCallback depends on the outer selector reference, so the wrapped function only changes when blockId changes. No logic paths were altered, only re-render trigger conditions. No files require special attention. The check-zustand-v5-selectors.ts script has minor edge cases around template-literal interpolation tracking and .reduce() false positives that have already been discussed on the PR. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Component renders] --> B{Zustand store hook call}
B -->|Whole-store subscription before PR| C[Subscribe to entire store]
B -->|Field-specific selector after PR| D[Subscribe to only needed fields]
C --> E[Any state change triggers re-render]
D --> F{Selector returns fresh object/array?}
F -->|Yes - BEFORE fix| G[New reference every render - re-render loop]
F -->|No - stable primitive or useShallow-wrapped| H[Shallow equality check - skip re-render if same values]
H --> I[Stable render]
Reviews (2): Last reviewed commit: "address comments" | Re-trigger Greptile |
|
@greptile |
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 8ca96c2. Configure here.

Summary
Type of Change
Testing
Tested manually
Checklist